package main

import (
	"fmt"
	"net/http"
)

// say hello to the world
func sayHello(w http.ResponseWriter, r *http.Request) {
	// n, errs := fmt.FPrintln(w,"hello world")
	_, _ = w.Write([]byte("hello golang web"))
}

func helloNexora(w http.ResponseWriter, r *http.Request) {
	// n, errs := fmt.FPrintln(w, "hello world")
	_, _ = w.Write([]byte("你好 Nexora"))
}

func helloKing(w http.ResponseWriter, r *http.Request) {
	//n, errs := fmt.FPrintln(w, "hello world")
	_, _ = w.Write([]byte("你好，king"))
}

func main() {
	// 12.9.组测一个处理函数
	http.HandleFunc("/", sayHello)
	http.HandleFunc("/nexora", helloNexora) // 处理其他 url
	http.HandleFunc("/king", helloKing)

	// 2.设置监听的TCP地址并启动服务
	// 参数1: TCP地址（IP+Port）
	// 参数2: handler handler参数一般会设为nil, 此时会使用DefaultServeMux
	err := http.ListenAndServe("0.0.0.0:9000", nil)
	if err != nil {
		fmt.Printf("http.ListenAndServe() 函数执行错误，错误为：%v\n", err)
		return
	}

}
